/* How to Hook with Logos
 Hooks are written with syntax similar to that of an Objective-C @implementation.
 You don't need to #include <substrate.h>, it will be done automatically, as will
 the generation of a class list and an automatic constructor.
 
 %hook ClassName
 
 // Hooking a class method
 + (id)sharedInstance {
 return %orig;
 }
 
 // Hooking an instance method with an argument.
 - (void)messageName:(int)argument {
 %log; // Write a message about this call, including its class, name and arguments, to the system log.
 
 %orig; // Call through to the original function with its original arguments.
 %orig(nil); // Call through to the original function with a custom argument.
 
 // If you use %orig(), you MUST supply all arguments (except for self and _cmd, the automatically generated ones.)
 }
 
 // Hooking an instance method with no arguments.
 - (id)noArguments {
 %log;
 id awesome = %orig;
 [awesome doSomethingElse];
 
 return awesome;
 }
 
 // Always make sure you clean up after yourself; Not doing so could have grave consequences!
 %end
 */


#import <UIKit/UIKit.h>
#pragma mark -

// Block internals.
typedef NS_OPTIONS(int, AspectBlockFlags) {
    AspectBlockFlagsHasCopyDisposeHelpers = (1 << 25),
    AspectBlockFlagsHasSignature          = (1 << 30)
};
typedef struct _AspectBlock {
    __unused Class isa;
    AspectBlockFlags flags;
    __unused int reserved;
    void (__unused *invoke)(struct _AspectBlock *block, ...);
    struct {
        unsigned long int reserved;
        unsigned long int size;
        // requires AspectBlockFlagsHasCopyDisposeHelpers
        void (*copy)(void *dst, const void *src);
        void (*dispose)(const void *);
        // requires AspectBlockFlagsHasSignature
        const char *signature;
        const char *layout;
    } *descriptor;
    // imported variables
} *AspectBlockRef;

#pragma mark -  腾讯视频
%hook QLTabBarController

- (void)viewDidLoad{
    %orig;
    
    UIWindow* keyWindow = [UIApplication sharedApplication].keyWindow;
    CGRect keyWindowFrame = keyWindow.bounds;
    UILabel* label = [[UILabel alloc] init];
    label.textColor = [UIColor redColor];
    label.backgroundColor = [UIColor blackColor];
    label.text = @"Welcome to your iPhone!";
    [keyWindow addSubview:label];
    [label sizeToFit];
    label.center = CGPointMake(CGRectGetMidX(keyWindowFrame), CGRectGetMidY(keyWindowFrame));
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [label removeFromSuperview];
    });
    
//    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Welcome" message:@"Welcome to your iPhone!" delegate:nil cancelButtonTitle:@"Thanks"
//                                          otherButtonTitles:nil];
//    [alert show];
}
%end

////-----------------------------------
//CHDeclareClass(TLUserManager)
//CHOptimizedMethod1(self, void, TLUserManager, canLoginWithHandleBlock,AspectBlockRef,arg1){
//    //CHOptimizedMethod1(self, void, TLUserManager, canLoginWithHandleBlock,void (^)(bool isLogin),arg1){
//    CHSuper1(TLUserManager, canLoginWithHandleBlock,arg1);
//}
//CHOptimizedMethod0(self, BOOL, TLUserManager, isLogining){
//    return true;
//}
//CHConstructor{
//    CHLoadLateClass(TLUserManager);
//    CHClassHook1(TLUserManager, canLoginWithHandleBlock);
//    CHClassHook0(TLUserManager, isLogining);
//}
#pragma mark -
#pragma mark -  番茄
%hook TLNetworkManager
- (void)requesWithReqModel:(id)a succ:(AspectBlockRef)succ fail:(AspectBlockRef)fail{
//    %orig(completionHandler);
    //    [NSMethodSignature signatureWithObjCTypes:completionHandler.descriptor.signature];
    //    void (^interception)(bool response) = ^(bool response){
    ////        NSLog(@"%@", response);
    //        completionHandler(response);
    //    };
    
    //    if (completionHandler){
    //        completionHandler(true);
    //    }
}
%end

%hook TLUserManager
- (void)canLoginWithHandleBlock:(void (^)(bool timer))completionHandler{
    %orig(completionHandler);

}
%end


//%hook AFURLSessionManager
//
//- (id)dataTaskWithRequest:(id)arg1 uploadProgress:(id)arg2 downloadProgress:(id)arg3 completionHandler:(void (^)(id response, id responseObject,  id error))completionHandler{
//
//    void (^interception)(NSURLResponse *response, id responseObject,  NSError * error) = ^(NSURLResponse *response, id responseObject,  NSError * error){
//        NSLog(@"%@", responseObject);
//        completionHandler(response, responseObject, error);
//    };
//
//    return %orig(arg1, arg2, arg3, interception);
//}
//
//%end
